 /**
 * Description: 角色权限vo
 * Copyright:Copyright 2018 nfky.com. All rights reserved
 * @author:xk
 * @since:0.0.1
 * Create at:2018-01-10 下午 19:40:19
 *  
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-01-10   xk       0.0.1     Initial
 */
package com.metro.paperless.sys.beans.vo;

import com.metro.utils.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.metro.paperless.sys.beans.entity.SysRoleMenuEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

 /**
 * 角色权限vo<br>
 *
 * @author xk
 * @since [0.0.1]
 * @version [0.0.1, 2018-01-10]
 */
@Data()
@EqualsAndHashCode(callSuper = false)
public class SysRoleMenu extends SysRoleMenuEntity{

     private String menuIds;
     //操作权限
     private String rightsIds;
     private Long[] menuIdArr;
     private String[] rightsArr;

     //columns END

     public void setMenuIds(String menuIds) {
         this.menuIds = menuIds;
         this.menuIdArr = StringUtil.split2LongArray(menuIds);
     }

     public void setRightsIds(String rightsIds) {
         this.rightsIds = rightsIds;
         if(rightsIds != null){
             String[] idArr = rightsIds.split(";");
             rightsArr = new String[idArr.length];
             for(int i = 0; i < idArr.length; i++){
                 rightsArr[i] = StringUtils.isBlank(idArr[i]) ? "*" : idArr[i];
             }
         }
     }


     /**
      * 构建角色权限对应关系列表
      * @return
      */
     public List<SysRoleMenu> buildRoleMenus(){
         if(this.menuIdArr != null && this.menuIdArr.length > 0){
             List<SysRoleMenu> list = new ArrayList<>();
             SysRoleMenu roleMenu = null;
             for (int i = 0; i < this.getMenuIdArr().length; i++) {
                 roleMenu = new SysRoleMenu();
                 roleMenu.setMenuId(this.getMenuIdArr()[i]);
                 roleMenu.setRoleId(this.getRoleId());
                 roleMenu.setRights(this.getRightsArr()[i]);
                 list.add(roleMenu);
             }
             return list;
         }
         return null;
     }
}
